package com.jbm.enterapplication.moduserpwd.view

import android.support.design.widget.TextInputLayout
import android.text.Editable
import android.text.TextWatcher
import android.view.View
import com.jbm.enterapplication.R
import com.jbm.enterapplication.activity.MainActivity
import com.jbm.enterapplication.moduserpwd.presenter.Chang_Presenter_Pwd
import kotlinx.android.synthetic.main.activity_chang_pwd.*
import kotlinx.android.synthetic.main.lz_titlehurdle.*


class ChangPwd : MainActivity(),View.OnClickListener ,Chang_View_Pwd_In{
    override fun getPwdJmErr(): TextInputLayout {
        return til_mima
    }

    override fun getPwdXmErr(): TextInputLayout {
        return til_xmima    }

    override fun getPwdQmErr(): TextInputLayout {
        return til_qrmima    }

    override fun getPwdJm(): String {
        return tiet_mima.editableText.toString()
    }

    override fun getPwdXm(): String {
        return tiet_xmima.editableText.toString()
    }

    override fun getPwdQm(): String {
        return tiet_qrmima.editableText.toString()
    }

    override fun onClick(v: View?) {
when(v?.id){
    R.id.register_manage_button_xiugai->{

        changpresentpwd?.getModiMiMa()

    }
    R.id.teleft->{
        finish()
    }
}
    }

    override fun getView(): Int {
        return R.layout.activity_chang_pwd
    }
var changpresentpwd: Chang_Presenter_Pwd?=null

    override fun getinit() {
        register_manage_button_xiugai.setOnClickListener(this)
        teleft.setOnClickListener(this)
        tiet_mima.addTextChangedListener(MyWatcher(tiet_mima))
        tiet_xmima.addTextChangedListener(MyWatcher(tiet_xmima))
        tiet_qrmima.addTextChangedListener(MyWatcher(tiet_qrmima))
        tetitle.text = "修改密码"
        changpresentpwd= Chang_Presenter_Pwd(this,this)
    }







    inner  internal class MyWatcher : TextWatcher {
        var view:View?=null
        constructor(view: View?) {
            this.view = view
        }
        override fun afterTextChanged(s: Editable?) {
            when(view?.id){
                R.id.tiet_mima ->{
                    if (s!!.length>=6){
                        til_mima.isErrorEnabled=false
                    }else if (!s.toString().equals(""))
                        til_mima.isErrorEnabled=false
                }
                R.id.tiet_xmima ->{
                    if (!s.toString().equals(""))
                        til_xmima.isErrorEnabled=false
                }
                R.id.tiet_qrmima ->{
                    if (!s.toString().equals(""))
                        til_qrmima.isErrorEnabled=false
                }
            }

        }

        override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {

        }

        override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {

        }

    }













}
